import 'dart:math';

import 'package:baselib/utils/image_util.dart';
import 'package:baselib/widgets/comm_app_bar.dart';
import 'package:baselib/widgets/gradient_card_view.dart';
import 'package:baselib/widgets/inkwell_button.dart';
import 'package:baselib/widgets/refresh_util.dart';
import 'package:flutter/material.dart';
import 'package:framelib/utils/color_util.dart';
import 'package:framelib/utils/drawable_util.dart';
import 'package:framelib/utils/px_util.dart';
import 'package:framelib/utils/string_util.dart';
import 'package:framelib/widgets/comm_widget_manager.dart';
import 'package:framelib/widgets/page_widget.dart';
import 'package:get/get.dart';
import 'package:module_business/module_contact/viewmodel/contact_view_model.dart';
import 'package:module_business/module_index/viewmodel/index_view_model.dart';
/**
 * 注册主页
 */
class ContactPage extends GetWidget<ContactViewModel> {
  @override
  Widget build(BuildContext context) {
    Get.put(ContactViewModel());
    return PageWidget.build(
        builder: (ContactViewModel model){
          return PageWidget.PageScaffoldWidget(
            isShowBg: true,
            appBar: CommAppBar(
              leadingWidth: PxUtil.instance.screenWidth,
              leading: Container(
                alignment: Alignment.centerLeft,
                margin: EdgeInsets.only(
                  left: PxUtil.instance.px_15,
                ),
                child: Text(
                  StringUtil.instance.Interest_Chat_channel,
                  style: TextStyle(
                    fontSize: PxUtil.instance.px_24,
                    fontWeight: FontWeight.bold
                  ),
                )
              ),
              backgroundColor: ColorUtil.instance.color_transparent,
            ),
            body: RefreshUtil.init(
              model.refreshController,
                  ()=>model.onRefresh(pageCur: model?.page=1),
                  null,
              _buildListUi(model),
              physics: ClampingScrollPhysics(),
              loadStatus: model?.loadStatus,
              enablePullDown: true,
              enablePullUp: false,
              isCanMoreData: false,
              onReFreshFunction:()=>model.onRefresh(pageCur: model?.page=1),
            ),
          );
        }
    );
  }

  Widget _buildListUi(ContactViewModel model) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        //sport
        Obx(() => _buildItemUi(model,DrawableUtil.instance.icon_chat_room_logo_sport,
            StringUtil.instance.Sport,
            model.sportChatRoomInfo.value.announcement?? StringUtil.instance.Sport_des,
            // model.sportChatRoomInfo.value.onlineUserCount??
                (265+Random().nextInt(100)))),
        //music
        Obx(() => _buildItemUi(model,DrawableUtil.instance.icon_chat_room_logo_music,StringUtil.instance.Music,
            model.musicChatRoomInfo.value.announcement??StringUtil.instance.Music_des,
            // model.musicChatRoomInfo.value.onlineUserCount??
                (265+Random().nextInt(100)))),
        //sport
        Obx(() => _buildItemUi(model,DrawableUtil.instance.icon_chat_room_logo_yago,StringUtil.instance.Yoga,
            model.yogaChatRoomInfo.value.announcement??StringUtil.instance.Yoga_des,
            // model.yogaChatRoomInfo.value.onlineUserCount??
                (265+Random().nextInt(100)))),
      ],
    );
  }

  _buildItemUi(ContactViewModel model,
      String cover,String type,String typeDes,int peopleNum,
      ) {
    return GradientCardView(
        margin: EdgeInsets.only(
          top: PxUtil.instance.px_5,
          bottom: PxUtil.instance.px_5,
          left: PxUtil.instance.px_20,
          right: PxUtil.instance.px_20,
        ),
        elevation: PxUtil.instance.px_0,
        borderRadius: BorderRadius.circular(PxUtil.instance.px_8),
        child: InkWellButton(
          onPressed: () => model.chatItemTap(type),
          child: Container(
              width: PxUtil.instance.screenWidth,
              alignment: Alignment.center,
              decoration: BoxDecoration(
                color: ColorUtil.instance.color_2F4072,
                borderRadius:
                BorderRadius.circular(PxUtil.instance.px_8),
              ),
              child: Row(
                children: [
                  Container(
                    margin: EdgeInsets.all(PxUtil.instance.px_10),
                    child: ImagesUtil.loadAssetImage(
                        cover,
                        height: PxUtil.instance.px_60,
                        fit: BoxFit.fitHeight
                    ),
                  ),
                  // GradientCardView(
                  //     margin: EdgeInsets.all(PxUtil.instance.px_10),
                  //     elevation: PxUtil.instance.px_0,
                  //     borderRadius: BorderRadius.circular(PxUtil.instance.px_8),
                  //     child: InkWellButton(
                  //       // onPressed: () => model.selectCover(),
                  //       child: Container(
                  //         width: PxUtil.instance.px_60,
                  //         height: PxUtil.instance.px_60,
                  //         alignment: Alignment.center,
                  //         decoration: BoxDecoration(
                  //           color: ColorUtil.instance.color_2F4072,
                  //           borderRadius:
                  //           BorderRadius.circular(PxUtil.instance.px_8),
                  //         ),
                  //         child: CommWidgetManager.buildCicleImagWidget(
                  //           cover??'',
                  //           placeholder:
                  //           DrawableUtil.instance.icon_default_head,
                  //           width: PxUtil.instance.px_60,
                  //           height: PxUtil.instance.px_60,
                  //           roundRadius: PxUtil.instance.px_8,
                  //           backgroundColor: ColorUtil.instance.color_f2f2f2,
                  //           padding: EdgeInsets.only(),
                  //           margin: EdgeInsets.only(),
                  //         ),
                  //       ),
                  //     )),
                  Expanded(child: Column(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        type??'',
                        style: TextStyle(
                            fontWeight: FontWeight.w500,
                            color: ColorUtil.instance.color_white,
                            fontSize: PxUtil.instance.px_16
                        ),
                      ),
                      SizedBox(height: PxUtil.instance.px_12,),
                      Text(
                        typeDes??'',
                        style: TextStyle(
                            fontWeight: FontWeight.w500,
                            color: ColorUtil.instance.color_b3cacaca,
                            fontSize: PxUtil.instance.px_12
                        ),
                      )
                    ],
                  )),
                  Column(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      ImagesUtil.loadAssetImage(
                          DrawableUtil.instance.icon_contact_commit,
                          width: PxUtil.instance.px_24
                      ),
                      SizedBox(height: PxUtil.instance.px_12,),
                      Row(
                        children: [
                          Text(
                            '${peopleNum}',
                            style: TextStyle(
                                fontWeight: FontWeight.w500,
                                color: ColorUtil.instance.color_white,
                                fontSize: PxUtil.instance.px_12
                            ),
                          ),
                          SizedBox(width: PxUtil.instance.px_5,),
                          Text(
                            '${StringUtil.instance.People}',
                            style: TextStyle(
                                fontWeight: FontWeight.w500,
                                color: ColorUtil.instance.color_b3cacaca,
                                fontSize: PxUtil.instance.px_12
                            ),
                          )
                        ],
                      )
                    ],
                  ),
                  SizedBox(width: PxUtil.instance.px_10,),
                ],
              )
          ),
        ));
  }
}
